package com.glory.huaweipda.adapter

import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.glory.huaweipda.R
import com.glory.huaweipda.bean.EqpLogBean

class SimpleAdapter(private val context: Context, private val data: ArrayList<EqpLogBean.Logmessagetextlist>) : RecyclerView.Adapter<SimpleAdapter.SimpleViewHolder>() {
    override fun onBindViewHolder(holder: SimpleViewHolder, position: Int) {
        holder.timeText.text = data[position].logtime
        holder.stateText.text = data[position].logmessagetext
        when(data[position].color){
            "red" ->{
                holder.timeText.setTextColor(Color.parseColor("#FF0000"))
                holder.stateText.setTextColor(Color.parseColor("#FF0000"))
            }
            "green" ->{
                holder.timeText.setTextColor(Color.parseColor("#00FF00"))
                holder.stateText.setTextColor(Color.parseColor("#00FF00"))
            }
            "black" ->{
                holder.timeText.setTextColor(Color.parseColor("#1C1C1C"))
                holder.stateText.setTextColor(Color.parseColor("#1C1C1C"))
            }
            "" ->{
                holder.timeText.setTextColor(Color.parseColor("#1C1C1C"))
                holder.stateText.setTextColor(Color.parseColor("#1C1C1C"))
            }
        }
    }

    override fun getItemCount(): Int = data.size

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SimpleViewHolder
            = SimpleViewHolder(
        LayoutInflater.from(context)
        .inflate(R.layout.item_journal_layout, parent, false))

    inner class SimpleViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        var timeText: TextView = view.findViewById(R.id.time_text)
        var stateText: TextView = view.findViewById(R.id.state_text)
    }
}